"""
input:
cities = {'San Francisco': 'US', 'London': 'UK',
          'Manchester': 'UK', 'Paris': 'France',
          'Los Angeles': 'US', 'Seoul': 'Kerea'}
output:
{'US': ['San Francisco', 'Los Angeles'], 'UK': [...], ...}
"""


def f1(d):
    """d:传入字典"""
    res = {}
    for k, v in d.items():
        if v in res:
            res[v].append(k)
        else:
            res[v] = [k]
    return res


if __name__ == '__main__':
    cities = {'San Francisco': 'US', 'London': 'UK',
              'Manchester': 'UK', 'Paris': 'France',
              'Los Angeles': 'US', 'Seoul': 'Kerea'}
    print(f1(cities))
